Programming Basics

Constructs Expression Exercise

These exercises are designed to evaluate your knowledge, comprehension and application of the programming constructs of expressions. A couple of the problems evaluate your analysis and synthesis of the programming basics discussed so far. It is expected that you should be able to correctly answer all or nearly all of the questions and problems presented. You should do these exercises by yourself. This exercise represents the most foundational and elementary information to be mastered by anyone involved with computer programming.

1. Evaluate the following expressions.

Expression

Value of Variable Var

Var := 10 % 3

 

Var := 0110 | 1010

 

Var := 27 < -34.0

 

Var := 3 – 5 * 6

 

Var := True and False

 

Var := 12 = (2 * 6)

 

Var := 2 + 3

 

Var := !True

 

Var := 15/3 = 2.5*2

 

Var := 21/4 (integer)

 

Var := 10110011<<5

 

Var := 1001 & 0101

 

Var := 21.0/4.0

 

Var := ~11100010

 

Var := False or True

 

Var := 15/3 != 2.5*2

 

Var := 1010 ^ 0110

 

Var := 345 > -43256

 

Var := False || False

 

Var := (12 <= 15) and (-419 >= -937)

 

Var := 10110011>>3

 

Var := (3 – 5) * 6 / -2

 

Var := (True && True) || (!True)

 

 

2. Why is left shift and right shift a quick multiplier and divider by 2^n?

 

3. What happens when you right shift a negative number? Is it a division by 2^n? Show what happens with this expression -50 >> 2.